import React from "react";
import {Redirect} from "react-router-dom";
import * as routerType from "@/constants/routerType";

import Login from "@/pages/login";
import VerifyLogin from "@/pages/verifyLogin";
import AdminError from "@/components/admin-error";

const user = JSON.parse(localStorage.getItem("admin-user")) || {};

const routes = [
  {
    path: "/",
    exact: true,
    render: () => {
      return (
        user.id ? <Redirect to={`/admin/home/u/${user.id}`}/> : <Redirect to="/admin/login"/>
      )
    }
  },
  {
    path: "/admin/login",
    component: Login
  },
  {
    path: "/admin/home/u/:id",
    type: routerType.HOME,
    component: VerifyLogin
  },
  {
    path: "/admin/add_article/u/:id/:a_id",
    type: routerType.ADD_ARTICLE,
    component: VerifyLogin
  },
  {
    path: "/admin/article_list/u/:id",
    type: routerType.ARTICLE_LIST,
    component: VerifyLogin
  },
  {
    path: "/admin/archives/u/:id",
    type: routerType.ARCHIVES,
    component: VerifyLogin
  },
  {
    path: "/admin/add_friend/u/:id/:f_id",
    type: routerType.ADD_FRIEND,
    component: VerifyLogin
  },
  {
    path: "/admin/friend_list/u/:id",
    type: routerType.FRIEND_LIST,
    component: VerifyLogin
  },
  {
    path: "/admin/wall/u/:id",
    type: routerType.WALL,
    component: VerifyLogin
  },
  {
    path: "/admin/add_music/u/:id/:m_id",
    type: routerType.ADD_MUSIC,
    component: VerifyLogin
  },
  {
    path: "/admin/music_list/u/:id",
    type: routerType.MUSIC_LIST,
    component: VerifyLogin
  },
  {
    path: "/admin/profile/u/:id",
    type: routerType.PROFILE,
    component: VerifyLogin
  },
  {
    path: "*",
    component: AdminError,
    userId: user.id
  }
]

export default routes;
